{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from scipy.stats import chi2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "percents = [0.95,0.90,0.5,0.1,0.05,0.01,0.005]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.003932</td>\n",
       "      <td>0.015791</td>\n",
       "      <td>0.454936</td>\n",
       "      <td>2.705543</td>\n",
       "      <td>3.841459</td>\n",
       "      <td>6.634897</td>\n",
       "      <td>7.879439</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.102587</td>\n",
       "      <td>0.210721</td>\n",
       "      <td>1.386294</td>\n",
       "      <td>4.605170</td>\n",
       "      <td>5.991465</td>\n",
       "      <td>9.210340</td>\n",
       "      <td>10.596635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.351846</td>\n",
       "      <td>0.584374</td>\n",
       "      <td>2.365974</td>\n",
       "      <td>6.251389</td>\n",
       "      <td>7.814728</td>\n",
       "      <td>11.344867</td>\n",
       "      <td>12.838156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.710723</td>\n",
       "      <td>1.063623</td>\n",
       "      <td>3.356694</td>\n",
       "      <td>7.779440</td>\n",
       "      <td>9.487729</td>\n",
       "      <td>13.276704</td>\n",
       "      <td>14.860259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.145476</td>\n",
       "      <td>1.610308</td>\n",
       "      <td>4.351460</td>\n",
       "      <td>9.236357</td>\n",
       "      <td>11.070498</td>\n",
       "      <td>15.086272</td>\n",
       "      <td>16.749602</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3          4          5          6\n",
       "0  0.003932  0.015791  0.454936  2.705543   3.841459   6.634897   7.879439\n",
       "1  0.102587  0.210721  1.386294  4.605170   5.991465   9.210340  10.596635\n",
       "2  0.351846  0.584374  2.365974  6.251389   7.814728  11.344867  12.838156\n",
       "3  0.710723  1.063623  3.356694  7.779440   9.487729  13.276704  14.860259\n",
       "4  1.145476  1.610308  4.351460  9.236357  11.070498  15.086272  16.749602"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([chi2.isf(percents,df=i) for i in range(1,50)])\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0.95</th>\n",
       "      <th>0.9</th>\n",
       "      <th>0.5</th>\n",
       "      <th>0.1</th>\n",
       "      <th>0.05</th>\n",
       "      <th>0.01</th>\n",
       "      <th>0.005</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.003932</td>\n",
       "      <td>0.015791</td>\n",
       "      <td>0.454936</td>\n",
       "      <td>2.705543</td>\n",
       "      <td>3.841459</td>\n",
       "      <td>6.634897</td>\n",
       "      <td>7.879439</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.102587</td>\n",
       "      <td>0.210721</td>\n",
       "      <td>1.386294</td>\n",
       "      <td>4.605170</td>\n",
       "      <td>5.991465</td>\n",
       "      <td>9.210340</td>\n",
       "      <td>10.596635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.351846</td>\n",
       "      <td>0.584374</td>\n",
       "      <td>2.365974</td>\n",
       "      <td>6.251389</td>\n",
       "      <td>7.814728</td>\n",
       "      <td>11.344867</td>\n",
       "      <td>12.838156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.710723</td>\n",
       "      <td>1.063623</td>\n",
       "      <td>3.356694</td>\n",
       "      <td>7.779440</td>\n",
       "      <td>9.487729</td>\n",
       "      <td>13.276704</td>\n",
       "      <td>14.860259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1.145476</td>\n",
       "      <td>1.610308</td>\n",
       "      <td>4.351460</td>\n",
       "      <td>9.236357</td>\n",
       "      <td>11.070498</td>\n",
       "      <td>15.086272</td>\n",
       "      <td>16.749602</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      0.950     0.900     0.500     0.100      0.050      0.010      0.005\n",
       "1  0.003932  0.015791  0.454936  2.705543   3.841459   6.634897   7.879439\n",
       "2  0.102587  0.210721  1.386294  4.605170   5.991465   9.210340  10.596635\n",
       "3  0.351846  0.584374  2.365974  6.251389   7.814728  11.344867  12.838156\n",
       "4  0.710723  1.063623  3.356694  7.779440   9.487729  13.276704  14.860259\n",
       "5  1.145476  1.610308  4.351460  9.236357  11.070498  15.086272  16.749602"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns=percents\n",
    "df.index=df.index+1\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('./chisqure_threshold.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 驱动器 D 中的卷没有标签。\n",
      " 卷的序列号是 9E74-5E37\n",
      "\n",
      " D:\\评分卡 的目录\n",
      "\n",
      "2020/05/25  08:50    <DIR>          .\n",
      "2020/05/25  08:50    <DIR>          ..\n",
      "2020/05/25  08:36    <DIR>          .ipynb_checkpoints\n",
      "2020/05/20  11:02       662,059,680 Anaconda3-5.3.0-Windows-x86_64.exe\n",
      "2020/05/25  08:50             6,535 chisqure_threshold.csv\n",
      "2020/05/22  09:15             2,893 sql.txt\n",
      "2020/05/21  16:30            27,789 test.csv\n",
      "2020/05/22  10:47            22,351 test2.csv\n",
      "2020/05/22  11:05            34,322 分箱.ipynb\n",
      "2020/05/22  11:34            28,583 分箱方法探索.ipynb\n",
      "2020/05/25  08:44            31,730 分箱方法探索2.ipynb\n",
      "2020/05/25  08:43             9,531 卡方值查表.ipynb\n",
      "2020/05/22  09:07           116,633 查看数据.ipynb\n",
      "2020/05/22  10:23           129,826 查看数据2.ipynb\n",
      "2020/05/22  10:32           152,464 查看数据2_PLOT.ipynb\n",
      "2020/05/22  10:58           127,267 查看数据3.ipynb\n",
      "2020/05/21  16:30            27,789 用户-测试2.0.csv\n",
      "              14 个文件    662,777,393 字节\n",
      "               3 个目录 11,329,695,744 可用字节\n"
     ]
    }
   ],
   "source": [
    "!dir"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
